//剩余可输入多少个字+textView上的label伪装成placeHolder
-(void)textViewDidChange:(UITextView *)textView{
NSInteger inputLength = 40 - self.textView.text.length;    
NSString * remainder = [NSString stringWithFormat:@"剩余输入%@字", @(inputLength)];    
NSMutableAttributedString * attString = [[NSMutableAttributedString alloc] initWithString:remainder];    
[attString addAttributes:@{NSForegroundColorAttributeName:[UIColor redColor], NSFontAttributeName:MyFont(14)} range:[remainder rangeOfString:[NSString stringWithFormat:@"%@", @(inputLength)]]];    
self.changeLabel.attributedText = attString;
 }
 
-(IBAction)touchOther:(UIControl *)sender {    
[self.textView resignFirstResponder];
 }
 
-(void)textViewDidEndEditing:(UITextView *)textView{   
 [self.view endEditing:YES];    
if (self.textView.text.length > 0) {        
self.promptLabel.hidden = YES;   
 } else {        
    self.promptLabel.hidden = NO;    
}
}

-(void)textViewDidBeginEditing:(UITextView *)textView{    
  self.promptLabel.hidden = YES;  

 }

//其实还有更好的方式,是在-(void)textViewDidChange:(UITextView *)textView中进行判断是否隐藏,关于这一类的伪装placeHolder,尽量都用label来进行,不要直接选择对textView本身的text进行操作

//超出textField限制范围时的label实时显示
NSString * remainder = [NSString stringWithFormat:@"已超出限定范围%@字", @(labs(inputLength))];
NSMutableAttributedString * attString = [[NSMutableAttributedString alloc] initWithString:remainder];
[attString addAttributes:@{NSForegroundColorAttributeName:[UIColor redColor], NSFontAttributeName:MyFont(14)} range:[remainder rangeOfString:[NSString stringWithFormat:@"%@", @(labs(inputLength))]]];
self.changeLabel.attributedText = attString;

ShevaKuilin
388 声望32 粉丝

世间好物不坚牢,彩云易碎琉璃脆。